﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Business.Enums;
using mozhi.smarterp.Business.Purchases.Requisition;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Business.Controllers.Purchases
{
    [RemoteService]
    [Route("api/v1/purchases/requisitions")]
    public class PurchaseRequisitionController : BusinessController
    {
        private IPurchaseRequisitionAppService _appService;

        public PurchaseRequisitionController(IPurchaseRequisitionAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<PurchaseRequisitionDto> GetAsync(Guid id)
        {
            return await _appService.GetAsync(id);
        }

        [HttpGet]
        public async Task<PagedResultDto<PurchaseRequisitionDto>> GetAsync(PurchaseRequisitonResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpPost]
        public async Task<PurchaseRequisitionDto> CreateAsync(PurchaseRequisitionCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<PurchaseRequisitionDto> UpdateAsync(PurchaseRequisitionUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }

        [HttpPut]
        [Route("{id}/status/{status}")]
        public async Task UpdateStatusAsync(Guid id , DocumentStatusType status)
        {
            await _appService.UpdateStatusAsync(id, status);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpPost]
        [Route("{id}/order")]
        public async Task<bool> PushOrderAsync(Guid id)
        {
            return await _appService.PushDownOrderAsync(id);
        }
    }
}
